<template>
    <!-- 添加或修改到货发票对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="供应商名称" prop="supplierName">
                                <el-input v-model="form.supplierName" placeholder="请输入供应商名称" disabled/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="供应商编码" prop="code">
                            <el-input v-model="form.code" placeholder="请输入供应商编码" disabled/>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="开户行行号" prop="hanghao">
                                <el-input v-model="form.hanghao" placeholder="请输入开户行行号" disabled/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="银行账号" prop="zhanghao">
                                <el-input v-model="form.zhanghao" placeholder="请输入银行账号" disabled/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="开户行" prop="kaihuhang">
                                <el-input v-model="form.kaihuhang" placeholder="请输入开户行" disabled/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="打款编号" prop="nos">
                            <el-input v-model="form.nos" placeholder="请输入打款编号"/>
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="打款金额" prop="money">
                                <el-input-number v-model="form.money" placeholder="请输入打款金额"/>
                            </el-form-item>
                        </el-col>
                        <!--<el-col :span="12">
                            <el-form-item label="发票日期" prop="fpDate">
                                <el-date-picker clearable
                                                v-model="form.fpDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择发票日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>-->
                        <el-col :span="24">
                          <el-form-item label="打款记录">
                            <file-upload v-model="form.ddSongfile"/>
                          </el-form-item>
                        </el-col>
                        <el-col :span="24">
                          <el-form-item label="备注" prop="remark">
                            <el-input v-model="form.remark" placeholder="请输入备注"/>
                          </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "FakuanForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/lvFukuan/lvFukuan/',
                    add:'/lvFukuan/lvFukuan/addFk',
                    edit:'/lvFukuan/lvFukuan/edit',
                    getBySupplierId:'/goodsSupplier/goodsSupplier/',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                  id: null,
                  delFlag: null,
                  createBy: null,
                  createTime: null,
                  updateBy: null,
                  updateTime: null,
                  remark: null,
                  ywType: null,
                  tax: null,
                  money: null,
                  shengyu: null,
                  code: null,
                  counts: null,
                  dunwei: null,
                  supplierId: null,
                  supplierName: null,
                  state: null,
                  hanghao: null,
                  zhanghao: null,
                  kaihuhang: null,
                  kaipiao: null,
                  kpfile: null,
                  guobangdan: null,
                  zhifahuo: null,
                  ddSongpeople: null,
                  ddSongfile: null,
                  ddDatepeople: null,
                  nos: null,
                  daohuoid: null,
                  daohuono: null,
                  caigouid: null,
                  caigouno: null,
                  daohuodate: null,
                  qinggouid: null,
                  qinggouno: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAddDk(caigouid,supplierId,caigouno) {
                getById(this.url.getBySupplierId, supplierId).then(response => {
                  this.form.supplierName=response.data.name;
                  this.form.code=response.data.code;
                  this.form.hanghao=response.data.taxNo;
                  this.form.kaihuhang=response.data.bankName;
                  this.form.zhanghao=response.data.bankNo;
                  this.form.caigouid=caigouid;
                  this.form.caigouno=caigouno;
                  this.form.supplierId=supplierId;

                  const now = new Date();
                  const year = now.getFullYear(); // 年份，例如：2021
                  const month = now.getMonth() + 1; // 月份，范围是0-11，需要+1，例如：1月为1
                  const day = now.getDate(); // 日期，例如：31
                  const hours = now.getHours(); // 小时，24小时制，例如：23
                  const minutes = now.getMinutes(); // 分钟，例如：59
                  const seconds = now.getSeconds();
                  this.form.nos=year+""+month+day+hours+minutes+seconds;

                });

                this.reset();
                this.open = true;
                this.title = "添加付款";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改付款";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
